<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑项目信息</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" readonly autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>选择资料库模板</label>
                        <div class="layui-input-block">
                            <select id="tempid" name="tempid" lay-filter="tempid" ></select>
                            <p class="error" id="tempid_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_engin_setmu,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                $("#name").val(data.name);

                var tempid_str = '<option value="">请选择</option>';
                var tempid = res.data.tempid;
                for (var key in tempid){
                    if(tempid[key].id == data.tempid){
                        tempid_str += '<option value="'+tempid[key].id+'" selected>'+tempid[key].name+'</option>';
                    }else{
                        tempid_str += '<option value="'+tempid[key].id+'">'+tempid[key].name+'</option>';
                    }
                }
                $("#tempid").html(tempid_str);
                render_from();
            }
        });

        form.on('select(tempid)', function(data){
            if(data.value == ''){
                $('#tempid_error').show().text('请选择');
                $('#tempid_error').parent().find('input').addClass('select_error');
            }else{
                $('#tempid_error').hide();
                $('#tempid_error').parent().find('input').removeClass('select_error');
            }

        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            if(data.field.tempid == ''){
                $('#tempid_error').show().text('请选择');
                $('#tempid_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#tempid_error').hide();
                $('#tempid_error').parent().find('input').removeClass('select_error');
            }
            if(!validRes){return false;}

            data.field.id = param_id;



            layer.confirm("<div class='tit'>是否确认更改模板？</div><div class='exp'>更改模板后将导致已上报文件无法查看,且不可恢复，请谨慎操作</div>", {
                    title:'操作确认',
                    icon: 3,
                    area:['450px','220px'],
                    btn:['确定']
                }, function(conindex){
                    facade.ajax({url: ask_engin_setmu, data:data.field}).done(function(res){
                        if (res.code === 2000) {
                            dataPostTimeOut();
                        }
                    });
                    layer.close(conindex);
                }
            )
            return false;
        });

    });

</script>
</body>
</html>
